import request from '@/utils/request'

export function saveDocumentFlow(data) {
  return request({
    url: '/api/xd/document_flow/save',
    method: 'post',
    data
  })
}

export function pageStartDocumentFlow(data) {
  return request({
    url: '/api/xd/document_flow/page_start',
    method: 'post',
    data
  })
}

export function pageParticipantDocumentFlow(data) {
  return request({
    url: '/api/xd/document_flow/page_participant',
    method: 'post',
    data
  })
}

export function signInProcessing(data) {
  return request({
    url: '/api/xd/document_flow/sign_in_processing',
    method: 'post',
    data
  })
}
export function effectiveProcessing(data) {
  return request({
    url: '/api/xd/document_flow/effective_processing',
    method: 'post',
    data
  })
}

/**
 * 签收功能
 * @param data
 * @returns {AxiosPromise}
 */
export function signFor(data) {
  return request({
    url: '/api/xd/document_flow/sign_for',
    method: 'post',
    data
  })
}

/**
 * 发行知识库列表
 * @param data
 * @returns {AxiosPromise}
 */
export function getRelease(data) {
  return request({
    url: '/api/xd/document_flow/get_release',
    method: 'post',
    data
  })
}

/**
 * 待办事项
 * @param data
 * @returns {AxiosPromise}
 */
export function pageTodo(data) {
  return request({
    url: '/api/xd/document_flow/page_todo',
    method: 'post',
    data
  })
}

/**
 * 待办事项_数量统计
 * @param data
 * @returns {AxiosPromise}
 */
export function pageTodoCount(data) {
  return request({
    url: '/api/xd/document_flow/page_todo_count',
    method: 'post',
    data
  })
}

/**
 * 任务页面数据获取
 * @param data
 * @returns {AxiosPromise}
 */
export function handleTaskPage(data) {
  return request({
    url: '/api/xd/document_flow/handle_task_page',
    method: 'post',
    data
  })
}

/**
 * 新增修订获取数据接口
 * @param data
 * @returns {AxiosPromise}
 */
export function getDocumentFlowNewAndModify(data) {
  return request({
    url: '/api/xd/document_flow_new/getDocumentFlowNewAndModify',
    method: 'post',
    data
  })
}

/**
 * 作废下载流程获取数据接口
 * @param data
 * @returns {AxiosPromise}
 */
export function getDocumentFlowPrintAndDrop(data) {
  return request({
    url: '/api/xd/document_flow_print/getDocumentFlowPrintAndDrop',
    method: 'post',
    data
  })
}

/**
 * 通过节点获取节点信息
 * @param data
 * @returns {AxiosPromise}
 */
export function nodeHandle(data) {
  return request({
    url: '/api/xd/document_flow_handle/node_handle',
    method: 'post',
    data
  })
}
/**
 * 通过文档属性获文档
 * @param data
 * @returns {AxiosPromise}
 */
export function getDocumentListByType(data) {
  return request({
    url: '/api/xd/document_flow/get_document_list_by_type',
    method: 'post',
    data
  })
}

/**
 * 获取当前节点的数字编码
 * @param val
 * @returns {*}
 */
export function getPhase(val) {
  var phase = {
    newApply: 1,
    applyApproval: 2, // 新增的审批流程
    adminAudit: 3,
    draft: 4,
    review: 5,
    revise: 6,
    format_audit: 7,
    audit: 8,
    approve: 9,
    release: 10
  }
  return phase[val]
}

export function getPhaseSmall(val) {
  var phase = {
    apply: 1,
    audit: 2,
    // review: 3,
    approve: 3,
    release: 4
  }
  return phase[val]
}

/**
 * 定义流程类型
 * @type {{"1": string, "2": string, "3": string, "4": string, "5": string}}
 */
const flowType = {
  1: '/flow/flow_new/',
  2: '/flow/flow_modify/',
  3: '/flow/flow_delete/',
  4: '/flow/flow_download/',
  5: '/flow/flow_borrow/'
}

/**
 * 获取各流程节点处理简单
 */
export function getNodesHandle(data) {
  return request({
    url: '/api/xd/document_flow_handle/simple_nodes_handle',
    method: 'post',
    data
  })
}

/**
 * 获取历史版本
 */
export function getHistoryData(data) {
  return request({
    url: '/api/fd/document/listDocumentMotifyHistoryInfo',
    method: 'post',
    data
  })
}

export function getFlow(val) {
  return flowType[val]
}

/**
 * 根据文件编号获取某流程某节点最新处理历史
 */

export function nodeHandleByCode(data) {
  return request({
    url: '/api/xd/document_flow_handle/node_handle_by_code',
    method: 'post',
    data
  })
}

/**
 * 查看历史记录
 */
export function nodesHandle(data) {
  return request({
    url: '/api/xd/document_flow_handle/nodes_handle',
    method: 'post',
    data
  })
}

/**
 * 流程作废，修订校验
 */
export function getFlowExist(data) {
  return request({
    url: '/api/xd/document_flow/get_flow_exist',
    method: 'post',
    data
  })
}

/**
 * 签收情况
 */
export function releaseCheck(data) {
  return request({
    url: '/api/xd/document_flow/release_check',
    method: 'post',
    data
  })
}

/**
 * 获取培训信息
 */
export function getTrainByDocumentFlow(data) {
  return request({
    url: '/api/xd/document_flow/get_train_by_document_flow',
    method: 'post',
    data
  })
}

/**
 * 获取起草部门/
 */
export function getDrafterUserGroup(data) {
  return request({
    url: '/api/xd/document_flow_handle/get_drafter_user_group',
    method: 'post',
    data
  })
}

/**
 * 终止流程
 * @data{documentFlowId:number}
 */
export function Termination(data) {
  return request({
    url: 'api/xd/document_flow_new/termination',
    method: 'post',
    data
  })
}

/**
 * 文件生效
 * @data{
  documentReleaseIds:number
}
 */
export function takeEffect(data) {
  return request({
    url: '/api/xd/document_flow/take_effect',
    method: 'post',
    data
  })
}
/**
 * 文件失效
 * @data{
  documentReleaseIds:number
}
 */
export function loseEffect(data) {
  return request({
    url: '/api/xd/document_flow/lose_effect',
    method: 'post',
    data
  })
}

/**
 * 取消流程
 * @data{
  documentReleaseIds:number
}
 */
export function pushCancelApply(data) {
  return request({
    url: '/api/xd/document_flow_cancel_request/apply',
    method: 'post',
    data
  })
}

/**
 * 取消流程审批
 * @data{
  documentReleaseIds:number
}
 */
export function pushAuditlApply(data) {
  return request({
    url: '/api/xd/document_flow_cancel_request/audit',
    method: 'post',
    data
  })
}

/**
 * 获取培训信息
 * @data{
  documentReleaseIds:number
}
 */
export function getDocumentInfoOfRelease(data) {
  return request({
    url: '/api/xd/document_flow/get_document_info_of_release',
    method: 'post',
    data
  })
}

/**
 * 获取台账信息
 * @data{
  documentReleaseIds:number
}
 */
export function pageLedger(data) {
  return request({
    url: '/api/xd/ledger/page_ledger',
    method: 'post',
    data
  })
}

/**
 * 获取打印台账
 * @data{
  documentReleaseIds:number
}
 */
export function generate(data) {
  return request({
    url: '/api/xd/ledger/generate',
    method: 'post',
    data
  })
}

/**
 * 获取发放台账
 * @data{
  documentReleaseIds:number
}
 */
export function pageLedgerRelease(data) {
  return request({
    url: '/api/xd/ledger/page_ledger_release',
    method: 'post',
    data
  })
}

/**
 * 获取受控台账
 * @data{
  documentReleaseIds:number
}
 */
export function pageLedgerEffect(data) {
  return request({
    url: '/api/xd/ledger/page_ledger_effect',
    method: 'post',
    data
  })
}
/**
 * 获取受控台账
 * @data{
  documentReleaseIds:number
}
 */
export function documentFlowListPreOptions() {
  return request({
    url: '/api/xd/document_flow/list_pre_options',
    method: 'get'
  })
}

/**
 * 批量签收
 * @data{
  documentReleaseIds:number
}
 */
export function pushBatchSignFor(data) {
  return request({
    url: '/api/xd/document_flow/sign_for_batch',
    method: 'post',
    data
  })
}


/**
 * 文件增加发放对象
 * @data{
  documentReleaseIds:number
}
 */
export function addReceive(data) {
  return request({
    url: '/api/xd/document_flow/add_receive',
    method: 'post',
    data
  })
}
